﻿using DevExpress.Utils;
using JXC.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraReports.Design;
using DevExpress.XtraTab;
using Microsoft.Office.Interop.Excel;

namespace JXC.Core
{
    public sealed class ChildWinManagement
    {
        private ChildWinManagement()
        {
        }

        public static bool ExistWin(System.Windows.Forms.Form MDIwin, string caption)
        {
            bool flag = false;
            foreach (System.Windows.Forms.Form mdiChild in MDIwin.MdiChildren)
            {
                if (mdiChild.Text == caption)
                {
                    flag = true;
                    mdiChild.Show();
                    mdiChild.Activate();
                    break;
                }
            }

            return flag;
        }

        public static void LoadMdiForm(DevExpress.XtraTab.XtraTabControl tab, Form f)
        {

            foreach (XtraTabPage page in tab.TabPages)
            {
                if (page.Name == f.Name)
                {
                    tab.SelectedTabPage = page;
                    return;
                }
            }
            XtraTabPage xpage = new XtraTabPage();
            xpage.Name = f.Name;
            xpage.Text = f.Text;
            f.Dock = DockStyle.Fill;
            f.FormBorderStyle = FormBorderStyle.None;
            f.TopLevel = false;
            f.Visible = true;
            xpage.Controls.Add(f);
            tab.TabPages.Add(xpage);
            tab.SelectedTabPage = xpage;
        }
    }
}
